package main.java.br.com.projeto.domain.dao;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import main.java.br.com.projeto.domain.entity.OrdemServico;

public class DaoOrdemServico extends Dao<OrdemServico> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6366788209736715221L;

	public DaoOrdemServico() {
		super(OrdemServico.class);
	}
	
	public List<OrdemServico> listByFilter(Long numero, String cliente, Date dataEmissao) {
		String hql = "select ordemServico from OrdemServico ordemServico "
				+ "where (ordemServico.numOs = :numero or :numero = 0) "
				+ "and (ordemServico.cliente.nome like '%' || cast(:cliente  as string) || '%' or :cliente = null) "
				+ "and (ordemServico.data = :dataEmissao or cast(:dataEmissao as date) = null)";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("numero", numero);
		parameters.put("cliente", cliente);
		parameters.put("dataEmissao", dataEmissao);

		return this.findOneResult(hql, parameters);
	}
	
}
